package org.xiaojl.modules.video.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.xiaojl.common.SessionUser;
import org.xiaojl.common.base.BaseController;
import org.xiaojl.config.easyui.PageBean;
import org.xiaojl.config.easyui.PageParam;
import org.xiaojl.modules.video.entity.Personalvideo;
import org.xiaojl.modules.video.service.PersonalvideoService;
import org.xiaojl.utils.ToolUtil;
import org.xiaojl.utils.WebUtil;

/**
 * <p>
 * 个人视频 前端控制器
 * </p>
 *
 * @author xiaojl
 * @since 2017-10-09
 */
@Controller
@RequestMapping("/video/personalvideo")
public class PersonalvideoController extends BaseController {
	private static final Logger log = LoggerFactory.getLogger(PersonalvideoController.class);
	private static final String basePagePath = "video/personalvideo/";
	
	@Autowired
	private PersonalvideoService personalvideoService;
	
	/**
	 * 进入列表页面
	 */
	@RequiresPermissions("video/personalvideo/manager")
	@RequestMapping("/manager")
	public String manager(Model model){
		SessionUser su = WebUtil.getSessionUser();
		model.addAttribute("sessionUser", su);
		
		return basePagePath+"list";
	}
	
	/**
	 * 查询列表数据(分页)
	 */
	@RequiresPermissions("video/personalvideo/manager")
	@RequestMapping("/dataGrid")
	public @ResponseBody Object dataGrid(PageParam pageParam, Personalvideo entity){
		PageBean<Personalvideo> pageBean = this.selectListPage(pageParam, entity, personalvideoService);
		
		return pageBean;
	}
	
	
	/**
	 * 删除
	 */
	@RequiresPermissions("video/personalvideo/delete")
	@RequestMapping("/delete")
	public @ResponseBody Object delete(Long id) {
		try {
			Personalvideo entity = personalvideoService.selectById(id);
			if (ToolUtil.isEmpty(entity)) {
				return operateError("删除数据时，无法获取想要删除的数据，id="+id);
			}
			
			personalvideoService.deleteById(id);
			
			return operateSuccess("删除成功!");
		} catch (Exception e) {
			log.error("删除数据时，出现异常:id="+id, e);
			return operateError("删除失败!");
		}
	}
	
}
